//
//  BDMallCollectionViewCell.m
//  BadBoy
//
//  Created by wen on 2016/12/26.
//  Copyright © 2016年 niusaibing. All rights reserved.
//

#import "BDMallCollectionViewCell.h"
#import "BDMallProductModel.h"
@interface BDMallCollectionViewCell ()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *moneyLabel;
@property (nonatomic, strong) UIImageView *coverImage;

@property (nonatomic, strong) UIView *bottomLineView;
@property (nonatomic, strong) UIView *rightLineView;

@end

@implementation BDMallCollectionViewCell

- (void)configeWithModel:(id)model needLeftLine:(BOOL)needLeftLine{
    BDMallProductModel *productModel = model;
    self.nameLabel.text = productModel.title;
    self.moneyLabel.attributedText = [self changePointStringColorWithMoney:productModel.money];
//    self.moneyLabel.attributedText = [self changePointStringColorWithPoint:productModel.point];
    [self.coverImage sd_setImageWithURL:[NSURL URLWithString:productModel.cover] placeholderImage:[UIImage imageNamed:@"shop_pic"]];
    
    self.rightLineView.hidden = needLeftLine;
}

-(NSMutableAttributedString *)changePointStringColorWithMoney:(CGFloat)money{
    NSString *str = [NSString stringWithFormat:ASLocalizedString(@"%@ 元"),@(money)];
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:str attributes:nil];
    NSRange range = [str rangeOfString:[NSString stringWithFormat:@"%@", @(money)]];
    NSRange secondRange = [str rangeOfString:ASLocalizedString(@"元")];
    [attribute addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"ff4f00"] range:range];
    //    [attribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:range];
    [attribute addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"767676"] range:secondRange];
    //    [attribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:secondRange];
    return attribute;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.nameLabel.font = [UIFont systemFontOfSize:14];
    self.nameLabel.frame = CGRectMake(10, 10, self.width - 20, 15);
    
    self.moneyLabel.font = [UIFont systemFontOfSize:13];
    [self.moneyLabel sizeToFit];
    self.moneyLabel.left = 10;
    self.moneyLabel.top = self.nameLabel.bottom + 10;
    
    self.coverImage.size = CGSizeMake(self.width - 20, self.height - self.moneyLabel.bottom);
    self.coverImage.bottom = self.height;
    self.coverImage.contentMode = UIViewContentModeScaleAspectFit;
    
    self.bottomLineView.frame = CGRectMake(0, 0, self.width, 0.5);
    self.bottomLineView.bottom = self.height;
    self.bottomLineView.backgroundColor = kBDColorGray;
    
    self.rightLineView.frame = CGRectMake(0, 0, 0.5, self.height);
    self.rightLineView.right = self.width;
    self.rightLineView.backgroundColor = kBDColorGray;
}

-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = KBDNameColor;
        _nameLabel.font = [UIFont systemFontOfSize:15];
        [self addSubview:_nameLabel];
    }
    return _nameLabel;
}

-(UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc]init];
        _moneyLabel.textColor = KBDColorBlue;
        _moneyLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:_moneyLabel];
    }
    return _moneyLabel;
}

-(UIImageView *)coverImage{
    if (!_coverImage) {
        _coverImage = [[UIImageView alloc]init];
        [self addSubview:_coverImage];
    }
    return _coverImage;
}

- (UIView *)bottomLineView{
    if (!_bottomLineView) {
        self.bottomLineView = [[UIView alloc] init];
        [self addSubview:_bottomLineView];
    }
    return _bottomLineView;
}

- (UIView *)rightLineView{
    if (!_rightLineView) {
        self.rightLineView = [[UIView alloc] init];
        [self addSubview:_rightLineView];
    }
    return _rightLineView;
}

@end
